﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;

namespace groupAnalyzer.Observers
{
    public class Observer
    {
        private LinkedList<ObserverClient> clients;
        private static Observer staticObserver; 
        public void deregister(ObserverClient client)
        {
            this.clients.Remove(client);
        }

        public void notifiy(Messages message, Object payLoad)
        {
            Console.WriteLine("notifing " + message);
            foreach(ObserverClient client in this.clients) {
                client.notify(message,payLoad);
            }
        }

        public void register(ObserverClient client)
        {
            this.clients.AddLast(client);
        }

        public Observer()
        {
            this.clients = new LinkedList<ObserverClient>();
        }

        public static Observer getGlobalObserver()
        {
            if (staticObserver == null)
            {
                staticObserver = new Observer();
            }
            return staticObserver;
        }
    }
}
